﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Commerce/Views/Shared/Backend.Master"
    Inherits="System.Web.Mvc.ViewPage<PagedList<IOrder>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    <%: "Orders".Localize() %>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h3 class="title">
        <%: "Orders".Localize() %></h3>
    <div class="command clearfix">
        <%: Html.ActionLink("Create new order".Localize(),"create",null,new {@class="button"}) %>
    </div>
    <div class="table-container">
        <table>
            <thead>
                <tr>
                    <th>
                        <%: "Order ID".Localize() %>
                    </th>
                    <th>
                        <%: "Customer".Localize() %>
                    </th>
                    <th class="numeral">
                        <%: "Quantity".Localize() %>
                    </th>
                    <th class="numeral">
                        <%: "Total".Localize() %>
                    </th>
                    <th>
                        <%: "Order date".Localize() %>
                    </th>
                    <th>
                        <%: "Status".Localize() %>
                    </th>
                    <th class="action">
                        <%: "View".Localize() %>
                    </th>
                </tr>
            </thead>
            <tbody>
                <% 
                    var currentUrl = this.Request.Url.ToString();
                    var color = true;
                    foreach (var item in this.Model)
                    {
                        color = !color;
                %>
                <tr <%= color?"even":"" %>>
                    <td>
                        <%: Html.ActionLink(item.Id.ToString(), "detail", new { id = item.Id, returnUrl = currentUrl }, null)%>
                    </td>
                    <td>
                        <% if (item.Customer != null)
                           { %>
                        <%: Html.ActionLink(item.Customer.FirstName + " " + item.Customer.LastName, "edit", "customer", new { id = item.Customer.Id, returnUrl = currentUrl }, null)%>
                        <%} %>
                    </td>
                    <td class="numeral">
                        <%: item.OrderItems.Count %>
                    </td>
                    <td class="numeral">
                        <%: (item.Total + item.ShippingCost + item.PaymentMethodCost + item.TotalTaxCost - item.TotalDiscount).ToString("c") %>
                    </td>
                    <td>
                        <%: item.OrderDate %>
                    </td>
                    <td class="status">
                        <%: ((OrderStatus)item.OrderStatus).ToString()%>
                    </td>
                    <td class="action">
                        <%: Html.ActionLink("View".Localize(), "detail", new { id = item.Id, returnUrl = currentUrl }, new { @class = "o-icon view" })%>
                    </td>
                </tr>
                <%}%>
            </tbody>
        </table>
        <div class="pager-wrap">
            <div class="pager">
                <%= Html.Pager(Model)%>
            </div>
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ScriptContent" runat="server">
    <%using (var loader = ClientLoader.RegisterInstance())
      {
          loader.Require("order.index.js");
      } %>
</asp:Content>
